<?php
namespace app\system\controller;

use app\common\model\UserModel;
use think\Controller;
use think\Cookie;
use think\Request;

class PublicController extends Controller
{
    private $userModel;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->userModel = new UserModel();
    }

    /**
     * 系统用户登录
     * @return mixed
     */
    public function Login()
    {
        return $this->fetch();
    }

    /**
     * 用户登录
     */
    public function doLogin(){
        if ($this->request->isAjax()) {
            try{
                $data   = $this->request->param();
                $result = $this->validate($data, ['account' => 'require', 'password' => 'require']);
                if (true !== $result) {
                    exception($result,40001);
                }
                $result = $this->userModel->checkLogin($data['account'], $data['password']);
                Cookie::set('systemDes',$result);
            } catch (\Exception $e){
                $this->error($e->getMessage());
            }
            $this->success('登录成功！', url('Index/index'));
        }else{
            $this->error('非法请求！');
        }
    }

}
